<template>
  <div>
    <div class="bg"></div>
    <van-nav-bar title="留言列表" class="navbar">
      <template #left>
        <van-icon
          name="arrow-left"
          class="icon"
          size="20"
          @click="onClickLeft"
        />
      </template>
    </van-nav-bar>
    <div class="wrapper">
      <div class="item" v-for="item in list" :key="item.id">
        <div class="username">
          {{ item.username }}
        </div>
        <div class="content">
          {{ item.content }}
        </div>
        <div class="time">
          {{ item.create_time | FormatTime }}
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      list: [],
    };
  },
  async created() {
    this.list = await this.getCommentList();
    this.list.reverse();
    console.log(this.list);
    console.log(new Date(this.list[0].create_time).getTime());
  },
  methods: {
    async getCommentList() {
      let res = await this.$http({
        url: "/comment",
      });
      return res;
    },
    onClickLeft() {
      this.$router.back();
    },
  },
};
</script>

<style scoped>
.navbar {
  position: sticky;
  top: 0;
  left: 0;
}
.icon {
  color: #808080;
}
.bg {
  background-color: #e7e6e6;
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
}
.item {
  background-color: #ffffff;
  width: 90%;
  margin: 0 auto;
  margin-top: 1.25rem;
  border-radius: 0.625rem;
  overflow: hidden;
  position: relative;
}
.username {
  font-size: 0.8125rem;
  background-color: #5a78ec;
  width: 4.6875rem;
  text-align: left;
  padding-left: 0.7rem;
  /* padding-right: 0.46875rem; */
  color: #ffffff;
  height: 1.25rem;
  line-height: 1.25rem;
}
.content {
  padding: 0.9375rem 1.25rem;
  font-size: 0.75rem;
}
.time {
  position: absolute;
  right: 5%;
  bottom: 5%;
  font-size: 0.875rem;
  color: #808080;
}
</style>